///
/// OSMAN TASKIN 2010 - VISUAL LIBRARIES
///


#include <WinUser32.mqh>

#define DESTROY 33050


/// FUNCTIONS //////////////////////////////////////////////
/*
void p2ObjectName(string objname) 
void p2ObjectName(string objname) 
void p2FontSize(int size) 
void p2Reset() 
void p2Corner(int which) 
void p2Font(string f) 
void p2(string mytext,color txtcolor=White,bool clearnow=false)
void p2XDistance(int d) 

void pObjectName(string objname) 
void pDefaultColor(color clr) 
void pFontSize(int size) 
void pReset() 
void pCorner(int which) 
void pFont(string f) 
void p(string mytext,color txtcolor=White,bool clearnow=false)

void  p4(string mytext,color clr=White,int pos=0)
string pxy(string mytext,color clr,int posx,int posy,int size)

void DelObjPref(string pref)   // delete all objects with this pref

void DrawBox(string namebox,datetime firsttime,double firstprice,datetime secondtime, double secondprice,color boxcolor,bool isbackground=false)
void DrawTrendLine(string name,datetime firsttime,double firstprice,datetime secondtime, double secondprice,color color)
void DrawLabel(string namebox,string content,int fntsize,datetime firsttime,double firstprice,color lblcolor, string font="Times New Roman")
void DrawVLine(string namebox,datetime firsttime,color boxcolor)
void DrawHLine(string namebox,double firstprice,color boxcolor,int window=0,int width=0)
void DrawHLine(string namebox,double firstprice,color boxcolor)
void DrawArrowDown(string namebox,datetime firsttime,double price,color boxcolor,int size=1)


int DrawCandle(double o,double h,double l,double c,int shift)
int opc()
void Destroy(string Meldung)
*/














// PRIVATES // PRIVATES // PRIVATES // PRIVATES // PRIVATES // PRIVATES // PRIVATES // PRIVATES // PRIVATES 
string lib_myobj = "uGj8J44gG7"; 
double lib_startinglevel = 2.0345; color lib_textcolor = White; int lib_startbarno = 5; int lib_spacebetweenlines = 10;
double lib_nextlinelevel = 0; int lib_counter = 0; int lib_bigcounter=0; int lib_fntsize=15; int lib_corner=0; int lib_corner2=0; string lib_font2="";

string lib_myobj2 = "roiroih48w"; 
double lib_startinglevel2 = 2.0345; color lib_textcolor2 = White; int lib_startbarno2 = 5; int lib_spacebetweenlines2 = 10;
double lib_nextlinelevel2 = 0; int lib_counter2 = 0; int lib_bigcounter2=0; int lib_fntsize2=15; string lib_font=""; 
int lib_xdistance2=500;


// P2// P2// P2// P2// P2// P2// P2// P2// P2// P2// P2// P2// P2// P2// P2// P2// P2// P2// P2
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void p2ObjectName(string objname) { lib_myobj2=objname; }
void p2DefaultColor(color clr) { lib_textcolor2=clr; }
void p2FontSize(int size) { lib_fntsize2=size; }
void p2Reset() { lib_counter2=0; }
void p2Corner(int which) { lib_corner2=which; }
void p2Font(string f) { lib_font2=f; }
void p2XDistance(int d) { lib_xdistance2=d; }
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Debug lines to graph
string p2(string mytext,color txtcolor=White,bool clearnow=false,string myname="")
{
   color tmpclr=White;
   string prefix="[p2#3]";

if (lib_nextlinelevel2 == 0) lib_nextlinelevel2 = lib_startinglevel2;
else lib_nextlinelevel2 = lib_nextlinelevel2 -lib_spacebetweenlines2*Point;

   lib_counter2++; if (lib_counter2>25) {lib_counter2=0;}
   lib_bigcounter2++; 
   if (lib_bigcounter2>150 || clearnow==true) {
      lib_bigcounter2=0; lib_nextlinelevel2 = lib_startinglevel2; lib_counter2=0;      
      for (int k=0;k<1;k++)
      {
      for (int i=0;i<ObjectsTotal();i++)
         {
         if (StringFind(ObjectName(i),prefix)>-1) { ObjectDelete(ObjectName(i)); }
         }      
      WindowRedraw(); 
      }
      }
   tmpclr=lib_textcolor2;
   if (txtcolor!=White) { tmpclr=txtcolor; }
   string objname=lib_myobj2+lib_counter2;
   if (myname!="") { objname=myname; }
   objname=prefix+objname;
   ObjectCreate(objname, OBJ_LABEL, 0, Time[lib_startbarno2], lib_nextlinelevel2);
   ObjectSet(objname, OBJPROP_CORNER,lib_corner2);
   ObjectSet(objname, OBJPROP_XDISTANCE, lib_xdistance2);
   ObjectSet(objname, OBJPROP_YDISTANCE, 10+lib_counter2*(lib_fntsize2+2));
   ObjectSet(objname, OBJPROP_COLOR, tmpclr);
   ObjectSet(objname, OBJPROP_BACK, true);
   ObjectSetText(objname, mytext, lib_fntsize2,lib_font2);
   return ( objname );
}
// P // P // P // P // P // P // P // P // P // P // P // P // P // P // P // P // P // P // P 
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void pObjectName(string objname) { lib_myobj=objname; }
void pDefaultColor(color clr) { lib_textcolor=clr; }
void pFontSize(int size) { lib_fntsize=size; }
void pReset() { lib_counter=0; }
void pCorner(int which) { lib_corner=which; }
void pFont(string f) { lib_font=f; }

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Debug lines to graph
void p(string mytext,color txtcolor=White,bool clearnow=false)
{
   color tmpclr=White;
if (lib_nextlinelevel == 0)
lib_nextlinelevel = lib_startinglevel;
else
lib_nextlinelevel = lib_nextlinelevel -lib_spacebetweenlines*Point;

   lib_counter++; if (lib_counter>35) {lib_counter=0;}
   lib_bigcounter++; if (lib_bigcounter>150  || clearnow==true) {
      lib_bigcounter=0;
      for (int i=1;i<50;i++) { ObjectDelete(lib_myobj+i); }
      }
   tmpclr=lib_textcolor;
   if (txtcolor!=White) { tmpclr=txtcolor; }
   ObjectCreate(lib_myobj+lib_counter, OBJ_LABEL, 0, Time[lib_startbarno], lib_nextlinelevel);
   ObjectSet(lib_myobj+lib_counter, OBJPROP_CORNER, lib_corner);
   ObjectSet(lib_myobj+lib_counter, OBJPROP_XDISTANCE, 100);
   ObjectSet(lib_myobj+lib_counter, OBJPROP_YDISTANCE, 10+lib_counter*(lib_fntsize+5));
   ObjectSet(lib_myobj+lib_counter, OBJPROP_COLOR, tmpclr);
   ObjectSet(lib_myobj+lib_counter, OBJPROP_BACK, false);
   ObjectSetText(lib_myobj+lib_counter, mytext, lib_fntsize,lib_font);
   return ( 0 );
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// DrawTrendLine("box1",Time[1],Close[1],Time[0],Open[0],Green);
// Draw TrendLine
void DrawTrendLine(string name,datetime firsttime,double firstprice,datetime secondtime, double secondprice,color boxcolor)
{
      ObjectDelete(name);
      ObjectCreate(name,OBJ_TREND,0,firsttime,firstprice,secondtime,secondprice);      
      ObjectSet(name,OBJPROP_COLOR,boxcolor); 
      ObjectSet(name,OBJPROP_TIMEFRAMES,opc());
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// DrawBox("box1",Time[1],Close[1],Time[0],Open[0],Green,false);
// Draw Rechtangle
void DrawBox(string namebox,datetime firsttime,double firstprice,datetime secondtime, double secondprice,color boxcolor,bool isbackground=false)
{
      ObjectDelete(namebox);
      ObjectCreate(namebox,OBJ_RECTANGLE,0,firsttime,firstprice,secondtime,secondprice);
      ObjectSet(namebox,OBJPROP_BACK,isbackground);         
      ObjectSet(namebox,OBJPROP_COLOR,boxcolor); 
      ObjectSet(namebox,OBJPROP_TIMEFRAMES,opc());
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// DrawLabel("lbl1","mycontent",12,Time[1],Close[1],Green);
// Draw Label 
void DrawLabel(string namebox,string content,int fntsize,datetime firsttime,double firstprice,color lblcolor, string font="Times New Roman")
{
      ObjectDelete(namebox);
      ObjectCreate(namebox,OBJ_TEXT,0,firsttime,firstprice);      
      ObjectSet(namebox,OBJPROP_COLOR,lblcolor); 
      ObjectSetText(namebox,content,fntsize,font, lblcolor);
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// DrawVLine("vline1",Time[1],0,color linecolor)
// Draw Vertical Line
void DrawVLine(string namebox,datetime firsttime,color boxcolor,int window=0)
{
      ObjectDelete(namebox);
      ObjectCreate(namebox,OBJ_VLINE,window,firsttime,0);      
      ObjectSet(namebox,OBJPROP_BACK,true);         
      ObjectSet(namebox,OBJPROP_COLOR,boxcolor); 
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// DrawHLine("hline1",High[1],color linecolor)
// Draw HorizontalLine
void DrawHLine(string namebox,double firstprice,color boxcolor,int window=0,int width=0)
{
      ObjectDelete(namebox);
      ObjectCreate(namebox,OBJ_HLINE,window,0,firstprice);      
      ObjectSet(namebox,OBJPROP_BACK,true);         
      ObjectSet(namebox,OBJPROP_COLOR,boxcolor); 
      if (width>0) ObjectSet(namebox,OBJPROP_WIDTH,width);
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// DrawArrowUp("thumb1",Time[1],High[1],Green)
void DrawArrowUp(string namebox,datetime firsttime,double price,color boxcolor,int size=1)
{
      ObjectDelete(namebox);
      ObjectCreate(namebox,OBJ_ARROW,0,firsttime,price);      
      ObjectSet(namebox,OBJPROP_COLOR,boxcolor); 
      ObjectSet(namebox,OBJPROP_ARROWCODE,SYMBOL_ARROWUP); ObjectSet(namebox,OBJPROP_TIMEFRAMES,opc());ObjectSet(namebox,OBJPROP_WIDTH,size);
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// DrawArrowDown("thumb1",Time[1],High[1],Red)
void DrawArrowDown(string namebox,datetime firsttime,double price,color boxcolor,int size=1)
{
      ObjectDelete(namebox);
      ObjectCreate(namebox,OBJ_ARROW,0,firsttime,price);      
      ObjectSet(namebox,OBJPROP_COLOR,boxcolor); 
      ObjectSet(namebox,OBJPROP_ARROWCODE,SYMBOL_ARROWDOWN);
      ObjectSet(namebox,OBJPROP_WIDTH,size); ObjectSet(namebox,OBJPROP_TIMEFRAMES,opc());
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Destroy(string Meldung)
{      
   int startbarno=5; double startinglevel = 2.0345;
   string n="qnjwrojqpwr";
   Meldung=Meldung+" E:"+GetLastError();   
   ObjectDelete(n);
   ObjectCreate(n, OBJ_LABEL, 0, Time[startbarno], startinglevel);
   ObjectSet(n, OBJPROP_CORNER, 0);
   ObjectSet(n, OBJPROP_XDISTANCE, 100);
   ObjectSet(n, OBJPROP_YDISTANCE, 150);
   ObjectSet(n, OBJPROP_COLOR, Red);
   ObjectSet(n, OBJPROP_BACK, true);
   ObjectSetText(n, "EA FORCED TO STOP ", 30);

   n=n+"1";
   ObjectDelete(n);
   ObjectCreate(n, OBJ_LABEL, 0, Time[startbarno], startinglevel);
   ObjectSet(n, OBJPROP_CORNER, 0);
   ObjectSet(n, OBJPROP_XDISTANCE, 100);
   ObjectSet(n, OBJPROP_YDISTANCE, 200);
   ObjectSet(n, OBJPROP_COLOR, White);
   ObjectSet(n, OBJPROP_BACK, true);
   ObjectSetText(n, Meldung, 30); 
   
   
	PostMessageA(WindowHandle(Symbol(), Period()), WM_COMMAND, DESTROY, 1);
	return;
}

//+------------------------------------------------------------------+
//| Object Period Constants
//+------------------------------------------------------------------+
int opc()
  {
  
   if (Period()==PERIOD_M1) { return(OBJ_PERIOD_M1); }
   if (Period()==PERIOD_M5) { return(OBJ_PERIOD_M5); }
   if (Period()==PERIOD_M15) { return(OBJ_PERIOD_M15); }
   if (Period()==PERIOD_M30) { return(OBJ_PERIOD_M30); }
   if (Period()==PERIOD_H1) { return(OBJ_PERIOD_H1); }
   if (Period()==PERIOD_H4) { return(OBJ_PERIOD_H4); }
   if (Period()==PERIOD_D1) { return(OBJ_PERIOD_D1); }
   if (Period()==PERIOD_W1) { return(OBJ_PERIOD_W1); }
   if (Period()==PERIOD_MN1) { return(OBJ_PERIOD_MN1); }     
   return(0);
  }



//------------------------------------------------------------
void DelObjPref(string str) 
{
string tn; int lens=StringLen(str);
for(int cnt=ObjectsTotal()-1;cnt>=0;cnt--)  { tn=ObjectName(cnt); if(StringSubstr(tn,0,lens)==str) ObjectDelete(tn); }

WindowRedraw();
return;
}
//------------------------------------------------------------


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void  p4(string mytext,color clr=White,int pos=0)
{
   string n="p3txt"+pos;
   ObjectCreate(n, OBJ_LABEL, 0, Time[lib_startbarno], lib_nextlinelevel);
   ObjectSet(n, OBJPROP_CORNER, 2);
   ObjectSet(n, OBJPROP_XDISTANCE, 100);
   ObjectSet(n, OBJPROP_YDISTANCE, 10+pos*26);
   ObjectSet(n, OBJPROP_COLOR, clr);
   ObjectSet(n, OBJPROP_BACK, false);
   ObjectSetText(n, mytext, 24);

}



/*
 ___                     ___              _ _     
|   \ _ _ __ ___ __ __  / __|__ _ _ _  __| | |___ 
| |) | '_/ _` \ V  V / | (__/ _` | ' \/ _` | / -_)
|___/|_| \__,_|\_/\_/   \___\__,_|_||_\__,_|_\___|
                                                  
*/
// DRAW CANDLE
int DrawCandle(double o,double h,double l,double c,int shift)
{
int clr=Brown;
int fromtime,totime;
//void DrawBox(string namebox,datetime firsttime,double firstprice,datetime secondtime, double secondprice,color boxcolor,bool isbackground=false)
if (c>o) clr=Green ;

if (shift>0) { fromtime=Time[shift]; totime=Time[shift-1]; }
else
   {
   fromtime=Time[shift]; totime=Time[0]+Period()*60;
   }

DrawBox("bx"+shift,fromtime,h,totime,l,clr,false);
DrawBox("bx2"+shift,fromtime,o,totime,c,clr,true);

}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
string pxy(string mytext,color clr,int posx,int posy,int size)
{
   string n="pxy3txt"+posx+posy;
   ObjectCreate(n, OBJ_LABEL, 0, Time[lib_startbarno], lib_nextlinelevel);
   ObjectSet(n, OBJPROP_CORNER, 0);
   ObjectSet(n, OBJPROP_XDISTANCE, posx);
   ObjectSet(n, OBJPROP_YDISTANCE, posy);
   ObjectSet(n, OBJPROP_COLOR, clr);
   ObjectSet(n, OBJPROP_BACK, false);
   ObjectSetText(n, mytext, size);
   return(n);
}



